package com.markerhub.controller;

import com.markerhub.common.dto.LoginDto;
import com.markerhub.common.lang.Result;
import com.markerhub.entity.User;
import com.markerhub.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;


@RestController
public class AccounController {

    @Autowired
    UserService userService;


    //登录
    @PostMapping("/login")
    public Result Login(@Validated @RequestBody LoginDto loginDto, HttpServletResponse response){
        return userService.Login(loginDto.getUsername(),loginDto.getPassword(),response);
    }

    //退出
    @RequiresAuthentication
    @GetMapping("/logout")
    public Result Login(){
        SecurityUtils.getSubject().logout();
        return Result.succ(null);
    }
}
